package collectionexercise02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortString {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("tom");
        list.add("jack");
        list.add("rose");
        list.add("jerry");
        list.add("Kobe");
        System.out.println("list"+list);
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length()-o2.length();
            }
        });
        System.out.println("list升序:"+list);

        list.sort((o1,o2)->o2.length()-o1.length());
        System.out.println("list降序:"+list);

        Collections.sort(list);//比较ASCII
        System.out.println("list升序："+list);
    }
}
